# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# Contains a stub Fuchsia bt-host component.
# Eventually the real bt-host component will be migrated here:
# https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/src/connectivity/bluetooth/core/bt-host/
# See https://fxbug.dev/321267390.

load("@fuchsia_infra//infra:infra.bzl", "fuchsia_cipd_releases")
load(
    "@fuchsia_sdk//fuchsia:defs.bzl",
    "fuchsia_cc_binary",
    "fuchsia_cc_test",
    "fuchsia_component",
    "fuchsia_component_manifest",
    "fuchsia_package",
    "fuchsia_platforms",
    "fuchsia_unittest_package",
)
load(
    "@fuchsia_sdk//fuchsia:licenses.bzl",
    "fuchsia_licenses_collection",
    "fuchsia_licenses_spdx",
)
load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT")

package(
    default_applicable_licenses = ["//pw_bluetooth_sapphire/fuchsia:license_fuchsia"],
    default_visibility = ["//pw_bluetooth_sapphire/fuchsia:__pkg__"],
)

exports_files(["README.fuchsia.md"])

fuchsia_cc_binary(
    name = "hello_world",
    srcs = [
        "hello_world.cc",
    ],
    deps = [
        "@fuchsia_sdk//pkg/fdio",
        "@fuchsia_sdk//pkg/syslog",
    ],
)

fuchsia_component_manifest(
    name = "manifest",
    src = "meta/bt-host.cml",
)

fuchsia_component(
    name = "component",
    manifest = ":manifest",
    deps = [":hello_world"],
)

fuchsia_cc_test(
    name = "hello_gtest",
    size = "small",
    srcs = ["hello_gtest.cc"],
    # TODO: b/310957361 - gtest not supported on device
    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
    deps = [
        "@com_google_googletest//:gtest_main",
        "@fuchsia_sdk//pkg/fdio",
        "@fuchsia_sdk//pkg/syslog",
    ],
)

fuchsia_unittest_package(
    name = "unittest_pkg",
    package_name = "bt-host-unittests",
    fuchsia_api_level = "HEAD",
    platform = fuchsia_platforms.x64,
    tags = ["manual"],
    unit_tests = [
        ":hello_gtest",
    ],
)

fuchsia_package(
    name = "pkg.x64",
    package_name = "bt-host",
    components = [
        ":component",
    ],
    fuchsia_api_level = "HEAD",
    platform = fuchsia_platforms.x64,
    tags = ["manual"],
)

fuchsia_package(
    name = "pkg.arm64",
    package_name = "bt-host",
    components = [
        ":component",
    ],
    fuchsia_api_level = "HEAD",
    platform = fuchsia_platforms.arm64,
    tags = ["manual"],
)

fuchsia_licenses_collection(
    name = "bt_host_x64_pkg_licenses_collection",
    root_target = ":pkg.x64",
    tags = ["manual"],
)

fuchsia_licenses_collection(
    name = "bt_host_arm64_pkg_licenses_collection",
    root_target = ":pkg.arm64",
    tags = ["manual"],
)

fuchsia_licenses_spdx(
    name = "bt_host_x64_licenses.spdx.json",
    document_namespace = "https://pigweed.dev/pw_bluetooth_sapphire/",
    licenses = ":bt_host_x64_pkg_licenses_collection",
    licenses_cross_refs_base_url = "https://pigweed.googlesource.com/pigweed/pigweed/+/refs/heads/main/pw_bluetooth_sapphire/fuchsia/",
    root_package_homepage = "https://pigweed.dev/pw_bluetooth_sapphire/",
    root_package_name = "bt-host",
    tags = ["manual"],
)

fuchsia_licenses_spdx(
    name = "bt_host_arm64_licenses.spdx.json",
    document_namespace = "https://pigweed.dev/pw_bluetooth_sapphire/",
    licenses = ":bt_host_arm64_pkg_licenses_collection",
    licenses_cross_refs_base_url = "https://pigweed.googlesource.com/pigweed/pigweed/+/refs/heads/main/pw_bluetooth_sapphire/fuchsia/",
    root_package_homepage = "https://pigweed.dev/pw_bluetooth_sapphire/",
    root_package_name = "bt-host",
    tags = ["manual"],
)

fuchsia_cipd_releases(
    name = "bt_host_x64_cipd",
    cipd_prefix = "fuchsia/prebuilt/bt-host",
    extra_content = {
        ":README.fuchsia.md": "README.fuchsia",
        ":bt_host_x64_licenses.spdx.json": "licenses.spdx.json",
    },
    pkg = ":pkg.x64",
)

fuchsia_cipd_releases(
    name = "bt_host_arm64_cipd",
    cipd_prefix = "fuchsia/prebuilt/bt-host",
    extra_content = {
        ":README.fuchsia.md": "README.fuchsia",
        ":bt_host_arm64_licenses.spdx.json": "licenses.spdx.json",
    },
    pkg = ":pkg.arm64",
)
